﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using FrameWork.Entity;
using FrameWork.web.Code;
using FrameWork.Components;


namespace FrameWork.web.Module.ITMS.Service.QueryService
{
    public partial class QueryService : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                lblRepNo.Text = "";
                lblRepName.Text = "";
                lblUnSolvDoc.Text = "1";
                lblSolvePSNNo.Text = "";
                lblSolvePSNName.Text = "";
                //txtDocDatBegin.Text = DateTime.Now.ToString("yyyy-MM") + "-01";
                lblDocDatBegin.Text = txtDocDatBegin.Text.Trim();
                //txtDocDatEnd.Text = DateTime.Now.ToString("yyyy-MM-dd");
                lblDocDatEnd.Text = txtDocDatEnd.Text.Trim();
                BindServerDoc();
            }
        }

        /// <summary>
        /// 绑定全部服务单
        /// </summary>
        private void BindServerDoc()
        {
            string repUserNo = lblRepNo.Text.Trim();
            string repUserName = lblRepName.Text.Trim();
            string docSolvPsnNo = lblSolvePSNNo.Text.Trim();
            string docSolvPsnName = lblSolvePSNName.Text.Trim();
            string docBeginTime = lblDocDatBegin.Text.Trim() + " 00:01";
            string docEndTime = lblDocDatEnd.Text.Trim() + " 23:59";
            bool statue;
            if (lblUnSolvDoc.Text.Trim() == "1")
            {
                statue = false;  
            }
            else
            {
                statue = true;
            }

            its_ServiceDocCs its = new its_ServiceDocCs();
     
            GvDoc.DataSource = its.ServiceDoc_Select(repUserNo, repUserName, docSolvPsnNo, docSolvPsnName, docBeginTime, docEndTime, statue, PagerDoc.CurrentPageIndex, PagerDoc.PageSize);
            GvDoc.DataBind();
            PagerDoc.RecordCount = its.ServiceDoc_SelectCount(repUserNo, repUserName, docSolvPsnNo, docSolvPsnName, docBeginTime, docEndTime, statue);
        }

        protected void PagerSolve_PageChanged(object sender, EventArgs e)
        {
            BindServerDoc();
        }

        protected void BtnQuery_Click(object sender, EventArgs e)
        {
            PagerDoc.CurrentPageIndex = 1;
            lblRepNo.Text = (string)Common.sink(txtRepNo.UniqueID, MethodType.Post, 20, 0, DataType.Str);
            lblRepName.Text = (string)Common.sink(txtRepName.UniqueID, MethodType.Post, 60, 0, DataType.Str);
            lblSolvePSNNo.Text = (string)Common.sink(txtSolvePSNNo.UniqueID, MethodType.Post, 20, 0, DataType.Str);
            lblSolvePSNName.Text = (string)Common.sink(txtSolvePSNName.UniqueID, MethodType.Post, 60, 0, DataType.Str);
            DateTime dtBegin = (DateTime)Common.sink(txtDocDatBegin.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            lblDocDatBegin.Text = dtBegin.ToString("yyyy-MM-dd") + " ";
            DateTime dtEnd = (DateTime)Common.sink(txtDocDatEnd.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            lblDocDatEnd.Text = dtEnd.ToString("yyyy-MM-dd");
            //txtDocDatBegin.Text = lblDocDatBegin.Text.Trim();
            //txtDocDatEnd.Text = lblDocDatEnd.Text.Trim();
            if (!chbUnSolvDoc.Checked)
            {
                lblUnSolvDoc.Text = "1";
            }
            else
            {
                lblUnSolvDoc.Text = "0";
            }
            BindServerDoc();
            
        }

        protected void lbtUnsolve_Click(object sender, EventArgs e)
        {
            try
            {

                //if (((LinkButton)sender).Parent.Parent.Parent.Parent.ID == "GVUnsolve")
                //{
                //    txtUid.Text = ((Label)((GridViewRow)((LinkButton)sender).Parent.Parent).FindControl("labUID")).Text.Trim();
                //    showTR();
                //    GetDocDetail(txtUid.Text.Trim());
                //}
                //else
                //{
                //    hindTR();
                //}
                string strServDocNo = ((LinkButton)sender).Text;
                txtDocNo.Text = strServDocNo;
                its_ServiceDocCs sdCs = new its_ServiceDocCs();
                its_ServiceDoc sd = new its_ServiceDoc();
                sd.ServDocNo = strServDocNo;
                DataTable dt = sdCs.ServiceSelect(sd);
                //txtServDocNo.Text = strServDocNo;
                txtRepContext.Text = dt.Rows[0]["RepContent"].ToString();
                txtRepTitle.Text = dt.Rows[0]["RepTitle"].ToString();
                txtSolution.Text = dt.Rows[0]["ItemMessage"].ToString().Replace("\\n", "\n");
                txtSolution.Text = txtSolution.Text.Replace("\\t", "\t");

                its_ServiceDocExtEntity ut = BusinessFacade.its_ServiceDocExtDisp(strServDocNo);
                string postilStr = ut.PostilDesc.Trim();
                txtPostil.Text = postilStr.Replace("\\n", "\n");
                txtPostil.Text = postilStr.Replace("\\t", "\t");

                if (ut.PostilPSN.Trim() != "")
                {
                    lblPostilPSN.Text = "批注人员:" + ut.PostilPSN;
                    lblPostilTime.Text = "批注时间:" + ut.PostilTime;
                }
                else
                {
                    lblPostilPSN.Text = "";
                    lblPostilTime.Text = "";
                }
                
                //drpServTrobType.SelectedValue = dt.Rows[0]["ServTrobType"].ToString();
                //drpServProbType.SelectedValue = dt.Rows[0]["ServProbType"].ToString();
            }
            catch
            {
                //
            }
        }

        protected void GvDoc_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    if (((Label)e.Row.FindControl("lblPostil")).Text == "1")
                    {
                        e.Row.BackColor = System.Drawing.Color.Red;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
